# the minimum version of CMake.
cmake_minimum_required(VERSION 3.5.0)
project(lottie-turbo)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()

set(CMAKE_SKIP_RPATH TRUE)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}
                    ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty
                    ${CMAKE_CURRENT_SOURCE_DIR}/render/drawing
                    ${CMAKE_CURRENT_SOURCE_DIR}/include
                    )

add_subdirectory(thirdparty)

add_library(lottie-turbo SHARED napi_init.cpp
                           lottie_bridge.cpp
                           task_pool/task_pool.cpp
                           datamanager/lottie_config_data.cpp
                           datamanager/lottie_config_data_bridge.cpp
                           datamanager/data_parse.cpp
                           cache/file_cache.cpp
                           cache/generator_key.cpp
                           cache/memory_cache.cpp
                           node/lottie_listener.cpp
                           controller/lottie_handler.cpp
                           controller/lottie_controller_bridge.cpp
                           animator/animator.cpp
                           datamanager/data_manager.cpp
                           common/napi_helper.cpp
                           node/lottie_xcomponent_node.cpp
                           render/lottie_render.cpp
                           render/lottie_render_gpu.cpp
                           render/lottie_render_layer.cpp
                           render/lottie_render_node.cpp
                           render/lottie_render_nativewindow.cpp
                           node/lottie_manager_map.cpp
                           render/drawing/brush.cpp
                           render/drawing/gly_path_bag.cpp
                           render/drawing/matrix.cpp
                           render/drawing/path.cpp
                           render/drawing/pen.cpp
                           render/drawing/rect.cpp
                           render/drawing/round_rect.cpp
                           render/drawing/shader_effect.cpp
                           render/drawing/color.cpp
                           render/drawing/canvas.cpp
                           render/drawing/bitmap.cpp
                           render/drawing/point.cpp
                           render/drawing/font_mgr.cpp
                           render/drawing/font.cpp
                           render/drawing/text_blob.cpp
                           render/drawing/draw_filter.cpp
                           render/drawing/text_typography.cpp
                           render/drawing/font_collection.cpp
                           )

target_link_libraries(lottie-turbo PUBLIC libace_napi.z.so
                                     libace_ndk.z.so
                                     rlottie::rlottie
                                     libhilog_ndk.z.so
                                     libnative_drawing.so
                                     libohresmgr.so
                                     librawfile.z.so
                                     librcp_c.so
                                     libohcrypto.so
                                     libnative_window.so
                                     libffrt.z.so
                                     libdeviceinfo_ndk.z.so
                                     boundscheck
                                     libimage_source.so
                                     libpixelmap.so
                                     )

if(CMAKE_BUILD_TYPE STREQUAL "Release")
    target_compile_definitions(lottie-turbo PUBLIC RELEASE_MODE=1)
    target_compile_options(lottie-turbo PUBLIC -s)
else()
    target_compile_definitions(lottie-turbo PUBLIC RELEASE_MODE=0)
    target_link_libraries(lottie-turbo PUBLIC libhitrace_ndk.z.so)
endif()
if("${OHOS_ARCH}" STREQUAL "arm64-v8a")
    target_link_directories(lottie-turbo PUBLIC ${HMOS_SDK_NATIVE}/sysroot/usr/lib/aarch64-linux-ohos)
elseif("${OHOS_ARCH}" STREQUAL "armeabi-v7a")
    target_link_directories(lottie-turbo PUBLIC ${HMOS_SDK_NATIVE}/sysroot/usr/lib/arm-linux-ohos)
elseif("${OHOS_ARCH}" STREQUAL "x86_64")
    target_link_directories(lottie-turbo PUBLIC ${HMOS_SDK_NATIVE}/sysroot/usr/lib/x86_64-linux-ohos)
endif()

set(LOTTIEC_INSTALL_PATH "${CMAKE_SOURCE_DIR}/../../../")
add_custom_command(TARGET lottie-turbo POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/include ${LOTTIEC_INSTALL_PATH}/include)